# -*- coding:utf-8
'''
作者: Jia
日期: 2022年04月21日
描述: https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/
'''

from typing import List


class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children


class Solution:
    def preorder(self, root: 'Node') -> List[int]:
        self.ans = []
        self.preorder_helper(root)
        return self.ans

    
    def preorder_helper(self, root: 'Node') -> List[int]:
        if root is None:
            return 
        self.ans.append(root.val)
        for node in root.children:
            self.preorder_helper(node)